﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class admin_addSB : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null && !Page.IsPostBack)
        {
            DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
            if (dv.Table.Rows.Count != 0)
            {
                tbxSBM.Text = dv[0]["s_Name"].ToString();//
                tbxSBBZ.Text = dv[0]["s_remark"].ToString();
                tbxSBZY.Text = dv[0]["s_zy"].ToString();
                ddlJS.Text = dv[0]["s_jfID"].ToString();
                ddlSBLX.Text = dv[0]["s_Class"].ToString();
            }
            else
            {
                // 没有找到这个ID的文章
            }
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        //s_jfID, s_class, s_Name, s_zy, s_remark
        if (Request.QueryString["id"] == null)
        {
            for (int i = 1; i <= int.Parse(tbxNum.Text); i++)
            {
                SqlDataSource1.Insert();
            }
                Response.Redirect("Editsb.aspx");
            
        }
        else
        {
            SqlDataSource1.Update();
            Response.Redirect("Editsb.aspx");
        }
    }
    protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
    {
        
            e.Command.Parameters[0].Value = ddlJS.Text;
            e.Command.Parameters[1].Value = ddlSBLX.Text;
            e.Command.Parameters[2].Value = tbxSBM.Text;
            e.Command.Parameters[3].Value = tbxSBZY.Text;
            e.Command.Parameters[4].Value = tbxSBBZ.Text;
        
    }
    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters[0].Value = Request.QueryString["id"];
    }
    protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        e.Command.Parameters[0].Value = ddlJS.Text;
        e.Command.Parameters[1].Value = ddlSBLX.Text;
        e.Command.Parameters[2].Value = tbxSBM.Text;
        e.Command.Parameters[3].Value = tbxSBZY.Text;
        e.Command.Parameters[4].Value = tbxSBBZ.Text;
        e.Command.Parameters[5].Value = Request.QueryString["id"].ToString();
    }
}